import 'package:dio/dio.dart';
import 'package:identification_photo/config/api_config.dart';
import 'package:identification_photo/config/constants.dart';
import 'package:identification_photo/network/dio_client.dart';

/// @Author  jingze
/// @Date  2022/5/17 19:32
/// @Title      baidu_ai_repository
/// @Todo  todo
/// @Version 1.0
/// 百度AI的网络访问类
class BaiduAiRepository {
  static Future<String> getToken() async {
    /// 第一个必穿参数 第二个第三个自己去百度Ai官网申请 免费额度一万次
    Map<String, dynamic> param = {
      "grant_type": "client_credentials",
      "client_id": clientId,
      "client_secret": clientSecret
    };
    Response<dynamic> response =
        await DioClient().doPost(Api.getToken, queryParameters: param);
    return response.data["access_token"];
  }

  /// 获取文件Base64的前景照 这里用的fromData传输
  static Future<String> getBase64(Map<String, dynamic> param) async {
    Response<dynamic> response = await DioClient().doPost(Api.uploadURL,
        data: FormData.fromMap(param),
        options: Options(contentType: "application/x-www-form-urlencoded"));
    return response.data["foreground"];
  }
}
